package com.stottlerhenke.simbionic.engine.parser;

import com.stottlerhenke.simbionic.engine.core.*;
import com.stottlerhenke.simbionic.api.SB_Exception;

import java.util.List;


public class SB_ExpArray extends SB_Expression
{
  public SB_ExpArray(List array)
  {
    _array = array;
  }

  public EExpressionType GetType(){ return EExpressionType.kArrayExpression; }

  public SB_Variable Evaluate(SB_Entity entity, SB_ExecutionFrame contextFrame) throws SB_Exception
  {
    SB_VarArray var = new SB_VarArray();

    int nCount = _array.size();
    for( int x = 0; x < nCount; x++ )
    {
      SB_Expression exp = (SB_Expression) _array.get(x);
      SB_Variable toAdd = exp.Evaluate(entity, contextFrame);
      var.push( toAdd );
    }

    return var;
  }

  /**
   * Replaces all instances of SB_Method in the expression tree that
   * match the name of newMethod.
   * @param newMethod the method with which to replace existing methods
   */
  public void replaceFunction(SB_Function newMethod)
  {
      for (int i=0; i < _array.size(); ++i)
      {
          ((SB_Expression)_array.get(i)).replaceFunction(newMethod);
      }
  }
  
  /**
   * @todo Probably should print more here
   *
   * @return
   */
  public String PrintTree() throws SB_Exception
  {
    return new String("array");
  }

  private List _array;
}